#ifndef data_H
#define data_H

#include <string>
#include <db_cxx.h>
#include "paper.pb.h"
#include <QUuid>

class BiblioDb {
public:
  // Constructor requires a path to the database,
  // and a database name.
  BiblioDb(std::string &path, std::string &dbName);
  // Our destructor just calls our private close method.
  ~BiblioDb() { close(); }  
  void createData();
  int getData(biblio::Paper*);
  int saveData(biblio::Paper*);
  int saveNewData(biblio::Paper*);
  int nextData(biblio::Paper*);
  int previousData(biblio::Paper*);
  qint64 generate_uuid();
  int get_attachment(biblio::Attachment*, biblio::Paper);
  void close();
  inline Db* &getDb() {return db_;}
private:
  Db *db_;
  Db *db_papers;
  Dbt keydbt;
  biblio::Key key;
  Dbc *cursorp;
  int cursor_ret;
  std::string dbFileName_;
  u_int32_t cFlags_;
  // Make sure the default constructor is private
  // We don't want it used.
  BiblioDb() {}
  // We put our database close activity here.
  void open();
  qint64 create_attachment_data(const char*);
};

#endif